<?php
namespace app\admin\controller;
class Set extends Common {


	//管理员表
	private $table_admin = "";

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
	}

	public function index(){
		$web_set_result = db('web_set')->field('telephone,type,logo,qr,banner')->find();

		if(request()->isAjax()){
			$telephone = input('telephone');
			$logo = request()->file('logo');
			$qr = request()->file('qr');
			$banner = request()->file('banner');
			$type = input('type');
			$data = array();
			if(!empty($telephone)){
				$data['telephone'] = $telephone;
			}

			if(!empty($logo)){
				$info = $logo->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
					$data['logo'] = $info->getSaveName();
				}
			}

			if(!empty($qr)){
				$info = $qr->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
//					$this->success('aa');
					$data['qr'] = $info->getSaveName();
				}
			}

			if(!empty($banner)){
				$info = $banner->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
					$data['banner'] = $info->getSaveName();
				}
			}

			if(!empty($type)){
				$data['type'] = $type;
			}

			$bool = db('web_set')->where(array('id'=>'1'))->update($data);

			if(!$bool)$this->error('修改失败');
			$this->success('修改成功!');
		}

		//用户等级
		$member_authority = db('member_authority')->where(['status'=>'1'])->select();

		$this->assign('web_set_result', $web_set_result);
		$this->assign('member_authority', $member_authority);
		return 	$this->fetch();
	}

	//关于我们
	public function about(){
		$web_set_result = db('web_set')->field('about')->find();

		if(request()->isAjax()){
			$about = input('about');
			$bool = db('web_set')->where(array('id'=>'1'))->update(array('about'=>$about));

			if(!$bool)$this->error('修改失败');
			$this->success('修改成功!');
		}

		$this->assign('web_set_result', $web_set_result);
		return 	$this->fetch();
	}

	//加入我们
	public function join(){
		$web_set_result = db('web_set')->field('join')->find();

		if(request()->isAjax()){
			$join = input('join');
			$bool = db('web_set')->where(array('id'=>'1'))->update(array('join'=>$join));

			if(!$bool)$this->error('修改失败');
			$this->success('修改成功!');
		}

		$this->assign('web_set_result', $web_set_result);
		return 	$this->fetch();
	}

	public function state(){
		if(request()->isAjax()){
			$state = input('state');
			$id = input('id');

			if($state){
				$data['state_name'] = $state;
				if(!$id){
					$bool = db('state')->insert($data);
				}else{
					$bool = db('state')->where('id',$id)->update($data);
				}
			}
			if(!$bool)$this->error('操作失败');
			$this->success('操作成功');
		}
		$data = db('state')->select();
		$this->assign('data', $data);
		return $this->fetch();
	}
}